﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demos.DesignPatterns._06_策略模式
{
    /// <summary>
    /// 具体策略：会员等级折扣
    /// </summary>
    public class MembershipDiscount : IDiscountStrategy
    {
        private readonly decimal _goldDiscount;
        private readonly decimal _silverDiscount;
        private readonly decimal _basicDiscount;

        public MembershipDiscount(decimal gold, decimal silver, decimal basic)
        {
            _goldDiscount = gold;
            _silverDiscount = silver;
            _basicDiscount = basic;
        }

        /// <summary>
        /// 固定金额折扣
        /// </summary>
        /// <param name="originalPrice"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public decimal ApplyDiscount(decimal originalPrice)
        {
            string memberShipLevel = GetUserMemberShipLevel();
            return memberShipLevel switch
            {
                "Gold" => originalPrice * (1 - _goldDiscount / 100),
                "Silver" => originalPrice * (1 - _silverDiscount / 100),
                "Basic" => originalPrice * (1 - _basicDiscount / 100),
                _ => originalPrice
            };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private static string GetUserMemberShipLevel()
        {
            // 实际项目中这里会查询用户会员等级
            // 这里返回模拟值
            return "Gold";
        }
    }
}
